﻿{include file="admin/header.htm"}
<form action="{$smarty.const.ADMIN_NAME}?m=admin&c=menu&a=add" method="post" name="myform" onSubmit="return checkForm()">
    <table cellpadding="2" cellspacing="1" class="table_form">
        <caption>{if $id>0}编辑菜单{else}添加菜单{/if}</caption>
        <tr>
            <th width="30%"><strong>父菜单</strong></th>    
            <td><span id="container"></span><span><a href="javascript:getChildMenu('container',0);">重选</a></span></td>
        </tr>
        <tr>
            <th width="30%"><strong>菜单名</strong></th>    
            <td><input type="text" name="menuname" value="{$menu.menu_name}"></td>
        </tr>
        <tr>
            <th width="30%"><strong>Controller Name</strong></th>    
            <td><input type="text" name="c" value="{$menu.c}"></td>
        </tr>  
        <tr>
            <th width="30%"><strong>Action Name</strong></th>    
            <td><input type="text" name="a" value="{$menu.a}"></td>
        </tr>
        <tr>
            <th width="30%"><strong>是否可见</strong></th>
            <td><input type="radio" name="notshow" value="0"{if !$menu.notshow} checked{/if}>是 <input type="radio" name="notshow" value="1"{if $menu.notshow eq 1} checked{/if}>否</td>
        </tr>
        <tr>
            <th><strong>权限设置</strong></th>
            <td id="groups">
                {if $id > 0}
                {if $parent eq 0 || ($parent neq 0 && $parentgids eq 0)}
                <p style="height:20px;width:90%;border-bottom:dashed 1px blue;padding-bottom:5px;margin-bottom:5px;">
                    <input type="checkbox" name="open" value="1"{if $groupids eq 0} checked{/if} style="vertical-align:middle;"/><span style="padding-left:1px;">不限</span><span style="color:red;">[勾选此处后虚线下方的选项将被忽略]</span>
                </p>
                {/if}
                {foreach $groups as $groupid => $group}
                {if $parent eq 0 || ($parent neq 0 && in_array($groupid, $parentgids)) || ($parent neq 0 && $parentgids eq 0)}
                <input type="checkbox" name="groups[]" value="{$groupid}"{if $groupids neq 0 && in_array($groupid, $groupids)} checked{/if} style="vertical-align:middle;"><span style="padding-left:4px;color:blue;">{$group.groupname}</span>
                {/if}
                {/foreach}
                {/if}
            </td>
        </tr>
        {if $id > 0 && $menu.isdir eq 1}
        <tr>
            <th><strong>应用到子菜单</strong></th>
            <td><input type="checkbox" name="usetochild" value="1" style="vertical-align:middle;"/><span style="color:red;">[是否对子菜单应用相同权限]</span></td>
        </tr>
        {/if}
        <tr>
            <th></th>
            <td>
                <input type="submit" name="doadd" class="button_style" value=" 确定 "> 
                <input type="reset" name="reset" class="button_style" value=" 清除 ">
            </td>
        </tr>
    </table>
    {if $id > 0}<input type="hidden" name="id" value="{$id}"/>{/if}
</form>
<p>&nbsp;<font color="#FF0000">注意：若此菜单不是文件夹，则程序将试图去访问：?m=admin&c=[controllername]&a=[actionname] 的链接</font></p>
{include file="admin/footer.htm"}
<script language="javascript">
function getChildMenu(c, mix) {
    var pid = mix == 0 ? 0 : mix.value;
    var url = '{$smarty.const.ADMIN_NAME}?m=admin&c=menu&a=add&op=getchild&pid='+pid;
    $.get(url,function(data){
        pid == 0 ? $('#'+c).html(data) : $('#'+c).append(data);
        if(mix != 0) mix.disabled = true;
    });
}

function checkForm() {
    if(myform.menuname.value == '') {
        alert('菜单名不能为空！');
        return false;
    }
    var parents = document.getElementsByName('parents[]');
    for(var i = 0; i < parents.length; i++) {
        parents[i].disabled = false;
    }
    
    return true;
}

{if $id eq 0}getChildMenu('container',0);{/if}
</script>